// 统一出口
import YYRequest from './request/index'
import { TIME_OUT, BASE_URL } from './request/config'
import cache from '@/utils/cache/cache'

const yRequest = new YYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptors: (config) => {
      // 携带token的拦截

      const token = cache.getCache('token')
      if (token) {
        config.headers!.Authorization = `Bearer ${token}`
      }

      return config
    },
    requestInterceptorsCatch: (err) => {
      return err
    },
    responseInterceptors: (config) => {
      return config
    },
    responseInterceptorsCatch: (err) => {
      return err
    }
  }
})
export default yRequest
